package com.vecspace.middleplatform.filemanagment.dao;

import java.util.Calendar;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;
import com.vecspace.constant.DBType;
import com.vecspace.data.model.FilterColumn;
import com.vecspace.data.model.Pagination;
import com.vecspace.data.model.RowMapper;
import com.vecspace.database.dao.AbstractDao;
import com.vecspace.database.model.QueryResult;
import com.vecspace.database.model.QuerySQL;
import com.vecspace.exception.HException;
import com.vecspace.middleplatform.filemanagment.pojo.UploadFile;
import com.vecspace.middleplatform.filemanagment.pojo.UploadFileSimple;
import com.vecspace.utils.UUIDUtil;

/**
 * 
 * 功能描述 
 * @类型名称 UploadFileDao
	* @author wanghua
 */
public class UploadFileDao extends AbstractDao{	
	private static final String TableSubPartSpltChar = "_T";
	private static final String UploadFileTableName = "TMS_UPLOAD_FILE";
	private static final String SelectFields = "ID,ACCESS_ID,STORAGE_ID,FILE_PATH,ORG_FILE_NAME,"
			+ "FILE_BYTES,FILE_EXT,UPLOADER,UPLOAD_TIME,APP_ID,"
			+ "TENANT_ID,ACCESS_TIMES,CLASSIFY_CODE1,CLASSIFY_CODE2,REMARKS,"
			+ "THUMBNAIL1_HEIGHT,THUMBNAIL1_WIDTH,THUMBNAIL1_BYTES,THUMBNAIL2_HEIGHT,THUMBNAIL2_WIDTH,THUMBNAIL2_BYTES";
	private Map<String, String> existsUploadFileTableMap = new ConcurrentHashMap<>();

	/**
	 * 根据多个查询条件执行分页查询 
	 * 建议此方法仅用于返回数据共页面Table展示数据使用。不要用于业务逻辑处理。
	 * @param queryFields	查询条件
	 * @param pageIndex	  页数 从1开始
	 * @param pageSize	   每页显示的数据条数,负数表示不分页
	 * @param sortField	  排序字段
	 * @param sortOrder	  排序方式 asc desc
	 * @return PageModel
	 * @throws Exception
	 * @reviewer
	 */
	public QueryResult<UploadFile> getUploadFileRecordExList(List<FilterColumn> queryFields,
			int pageIndex, int pageSize, String sortField, String sortOrder, String year) throws Exception {
		String tableName = "tms_upload_file_t" + year.trim();
		try {
			String sql = "select * from " + tableName + " where 1=2";
			dao.queryString(sql);//判断tableName是否存在
		} catch (Exception e) {
			return new QueryResult<UploadFile>();
		}

		QuerySQL querySql = new QuerySQL();
		
		querySql.setQueryColumns("t1.ID,t1.ACCESS_ID,t1.STORAGE_ID,t1.FILE_PATH,t1.ORG_FILE_NAME,\r\n" + 
				"t1.FILE_BYTES,t1.FILE_EXT,t1.UPLOADER,t1.UPLOAD_TIME,t1.APP_ID,\r\n" + 
				"t1.TENANT_ID,t1.ACCESS_TIMES, t1.CLASSIFY_CODE1,t1.CLASSIFY_CODE2,t1.REMARKS,"
				+ "t1.THUMBNAIL1_HEIGHT,t1.THUMBNAIL1_WIDTH,t1.THUMBNAIL1_BYTES,t1.THUMBNAIL2_HEIGHT,t1.THUMBNAIL2_WIDTH,t1.THUMBNAIL2_BYTES,t2.STORAGE_NAME");
		querySql.setTables(tableName+" t1 left join tms_upload_file_storage t2 on t1.STORAGE_ID=t2.ID");
		
		if(queryFields != null) {
			//给列名指定表限定名
			for(FilterColumn field : queryFields) {
				String propName = field.getColumnName();
				String columnName = propName;
				if(!columnName.contains(".")) {
					columnName = "t1."+columnName;
					field.setColumnName(columnName);
				}
			}
		}

		if(StringUtils.isNotEmpty(sortField) && !sortField.contains(".")){ //特殊约定：如果sortField包含.号，则不对其进行处理，如 t1.CATALOG_NAME,t1.NAME
			if(!sortField.contains(".")) {
				sortField = "t1." + sortField;
			}
		}

		if(sortOrder == null) sortOrder = "";

		//处理oracle排序不稳定的问题（排序字段不是唯一性字段时，分页会有问题，多页的数据是一样的）
		if(StringUtils.isNotEmpty(sortField)){
			sortField = sortField+ " " + sortOrder +",t1.UPLOAD_TIME DESC,t1.ID";//保证排序字段的唯一性
		}else{
			sortField = "t1.UPLOAD_TIME DESC,t1.ID";//保证排序字段的唯一性
		}
		querySql.setOrderby(sortField);
		querySql.addQueryFilter(queryFields);
		QueryResult<UploadFile> queryResult = dao.queryEntities(UploadFile.class, querySql, new Pagination(pageIndex, pageSize));
		
		return queryResult;
	}

	/**根据当前时间获取表名，表名格式：TMS_UPLOAD_FILE_yyyy ，比如：TMS_UPLOAD_FILE_2020
	 * 如果数据表还不存在，则创建它
	 * @return 
	 * @author  wanghua
	 * @throws Exception 
	 * @reviewer  
	 */
	private String[] getTableNameAndCreateTable() throws Exception {
		Calendar calendar = Calendar.getInstance();
		int year = calendar.get(Calendar.YEAR);
//		int month = calendar.get(Calendar.MONTH) + 1;
//		String monthStr = ""+month;
//		if(monthStr.length() == 1) {
//			monthStr = "0" + monthStr;
//		}
		String tableSubPart = TableSubPartSpltChar + year;
		String tableName = UploadFileTableName + tableSubPart;//+monthStr;//TMS_UPLOAD_FILE_T2020
		if(!existsUploadFileTableMap.containsKey(tableName)) {
			synchronized (UploadFileTableName) {
				if(!existsUploadFileTableMap.containsKey(tableName)) {
					try {
						createTable(tableName);
					}catch(Exception ex) {
						//表已经存在，不需要抛出异常
					}
					String sql = "select * from " + tableName + " where 1=2";
					dao.queryString(sql);//判断tableName是否存在
					existsUploadFileTableMap.put(tableName, tableName);
				}
			}
		}
		return new String[] {tableName, tableSubPart};
	}

	private void createTable(String tableName) throws Exception {
		if(DBType.MYSQL.equals(DBType.getActiveDB())) {
			createTableMySQL(tableName);
		}else if(DBType.POSTGRE.equals(DBType.getActiveDB())) {
			createTablePostgreSQL(tableName);
		}else if(DBType.ORACLE.equals(DBType.getActiveDB())) {
			createTableOracle(tableName);
		}else if(DBType.DERBY.equals(DBType.getActiveDB())) {
			createTableDerby(tableName);
		}else throw new HException("非预期的数据库类型："+DBType.getActiveDB());
	}

	private void createTableMySQL(String tableName) throws Exception {
		tableName = tableName.toUpperCase();
		String ddl = "create table " + tableName + "(\r\n" + 
				"   ID                   varchar(32) not null,\r\n" + 
				"   ACCESS_ID            varchar(64) comment '访问ID',\r\n" + 
				"   STORAGE_ID           varchar(32) not null comment '存储位置ID',\r\n" + 
				"   FILE_PATH            varchar(256) not null comment '存储路径（含文件名）',\r\n" + 
				"   ORG_FILE_NAME        varchar(256) comment '原文件名',\r\n" + 
				"   FILE_BYTES            bigint not null comment '文件字节数',\r\n" + 
				"   FILE_EXT             varchar(10) comment '文件后缀名（小写,不带点号）',\r\n" + 
				"   UPLOADER             varchar(50) comment '文件上传人ID',\r\n" + 
				"   UPLOAD_TIME          datetime comment '上传时间',\r\n" + 
				"   APP_ID               varchar(64) not null comment '所属应用系统ID',\r\n" + 
				"   TENANT_ID            varchar(64) not null comment '所属租户ID',\r\n" + 
				"   ACCESS_TIMES         bigint comment '访问次数',\r\n" + 
				"   CLASSIFY_CODE1       varchar(64) comment '文件分类码1',\r\n" + 
				"   CLASSIFY_CODE2       varchar(64) comment '文件分类码2',\r\n" + 
				"   THUMBNAIL1_HEIGHT    smallint comment '缩略图1高度',\r\n" + 
				"   THUMBNAIL1_WIDTH     smallint comment '缩略图1宽度',\r\n" + 
				"   THUMBNAIL1_BYTES     int comment '缩略图1字节数',\r\n" + 
				"   THUMBNAIL2_HEIGHT    smallint comment '缩略图2高度',\r\n" + 
				"   THUMBNAIL2_WIDTH     smallint comment '缩略图2宽度',\r\n" + 
				"   THUMBNAIL2_BYTES     int comment '缩略图2字节数',\r\n"+
				"   REMARKS              varchar(256) comment '备注',\r\n" + 
				"   RECORD_EDIT_FLAG     tinyint comment '编辑标记 0初始状态 1锁定状态 2重新编辑状态',\r\n" + 
				"   primary key (ID)\r\n" + 
				")";
		dao.execute(ddl);

		ddl = "create unique index IX1_" + tableName + " on " + tableName + "(ACCESS_ID)";
		dao.execute(ddl);

		ddl = "create index IX2_" + tableName + " on " + tableName + "(APP_ID,TENANT_ID)";
		dao.execute(ddl);

		ddl = "create index IX3_" + tableName + " on " + tableName + "(APP_ID,CLASSIFY_CODE1,CLASSIFY_CODE2)";
		dao.execute(ddl);
	}
	
	private void createTablePostgreSQL(String tableName) throws Exception {
		tableName = tableName.toUpperCase();
		String ddl = "create table " + tableName + "(\r\n" + 
				"   ID                   varchar(32) not null,\r\n" + 
				"   ACCESS_ID            varchar(64) ,\r\n" + 
				"   STORAGE_ID           varchar(32) not null ,\r\n" + 
				"   FILE_PATH            varchar(256) not null ,\r\n" + 
				"   ORG_FILE_NAME        varchar(256) ,\r\n" + 
				"   FILE_BYTES            int8 not null ,\r\n" + 
				"   FILE_EXT             varchar(10) ,\r\n" + 
				"   UPLOADER             varchar(50) ,\r\n" + 
				"   UPLOAD_TIME          datetime ,\r\n" + 
				"   APP_ID               varchar(64) not null ,\r\n" + 
				"   TENANT_ID            varchar(64) not null ,\r\n" + 
				"   ACCESS_TIMES         int8 ,\r\n" + 
				"   CLASSIFY_CODE1       varchar(64) ,\r\n" + 
				"   CLASSIFY_CODE2       varchar(64) ,\r\n" + 
				"   THUMBNAIL1_HEIGHT    int2 ,\r\n" + 
				"   THUMBNAIL1_WIDTH     int2 ,\r\n" + 
				"   THUMBNAIL1_BYTES     int4 ,\r\n" + 
				"   THUMBNAIL2_HEIGHT    int2 ,\r\n" + 
				"   THUMBNAIL2_WIDTH     int2 ,\r\n" + 
				"   THUMBNAIL2_BYTES     int4 ,\r\n"+
				"   REMARKS              varchar(256) ,\r\n" + 
				"   RECORD_EDIT_FLAG     int2 ,\r\n" + 
				"   constraint PK_"+tableName+" primary key (ID)\r\n" + 
				")";
		dao.execute(ddl);

		ddl = "create unique index IX1_" + tableName + " on " + tableName + "(ACCESS_ID)";
		dao.execute(ddl);

		ddl = "create index IX2_" + tableName + " on " + tableName + "(APP_ID,TENANT_ID)";
		dao.execute(ddl);

		ddl = "create index IX3_" + tableName + " on " + tableName + "(APP_ID,CLASSIFY_CODE1,CLASSIFY_CODE2)";
		dao.execute(ddl);
	}

	private void createTableOracle(String tableName) throws Exception {
		tableName = tableName.toUpperCase();
		String ddl = "create table " + tableName + "  (\r\n" + 
				"   ID                   VARCHAR2(32)                    not null,\r\n" + 
				"   ACCESS_ID            VARCHAR2(64),\r\n" + 
				"   STORAGE_ID           VARCHAR2(32)                    not null,\r\n" + 
				"   FILE_PATH            VARCHAR2(256)                   not null,\r\n" + 
				"   ORG_FILE_NAME        VARCHAR2(256),\r\n" + 
				"   FILE_BYTES            NUMBER(15)                         not null,\r\n" + 
				"   FILE_EXT             VARCHAR2(10),\r\n" + 
				"   UPLOADER             VARCHAR2(50),\r\n" + 
				"   UPLOAD_TIME          DATE,\r\n" + 
				"   APP_ID               VARCHAR2(64)                    not null,\r\n" + 
				"   TENANT_ID            VARCHAR2(64)                    not null,\r\n" + 
				"   ACCESS_TIMES         NUMBER(15),\r\n" + 
				"   CLASSIFY_CODE1       VARCHAR2(64),\r\n" + 
				"   CLASSIFY_CODE2       VARCHAR2(64),\r\n" + 
				"   THUMBNAIL1_HEIGHT    NUMBER(4),\r\n" + 
				"   THUMBNAIL1_WIDTH     NUMBER(4),\r\n" + 
				"   THUMBNAIL1_BYTES     NUMBER(9),\r\n" + 
				"   THUMBNAIL2_HEIGHT    NUMBER(4),\r\n" + 
				"   THUMBNAIL2_WIDTH     NUMBER(4),\r\n" + 
				"   THUMBNAIL2_BYTES     NUMBER(9),\r\n"+
				"   REMARKS              VARCHAR2(256),\r\n" + 
				"   RECORD_EDIT_FLAG     NUMBER(4),\r\n" + 
				"   constraint PK_TMS_UPLOAD_FILE primary key (ID)\r\n" + 
				")";
		dao.execute(ddl);

		ddl = "create unique index IX1_" + tableName + " on " + tableName + "(ACCESS_ID)";
		dao.execute(ddl);

		ddl = "create index IX2_" + tableName + " on " + tableName + "(APP_ID,TENANT_ID)";
		dao.execute(ddl);

		ddl = "create index IX3_" + tableName + " on " + tableName + "(APP_ID,CLASSIFY_CODE1,CLASSIFY_CODE2)";
		dao.execute(ddl);
	}

	private void createTableDerby(String tableName) throws Exception {
		tableName = tableName.toUpperCase();
		String ddl = "create table " + tableName + "  (\r\n" + 
				"   ID                   VARCHAR(32)                    not null,\r\n" + 
				"   ACCESS_ID            VARCHAR(64),\r\n" + 
				"   STORAGE_ID           VARCHAR(32)                    not null,\r\n" + 
				"   FILE_PATH            VARCHAR(256)                   not null,\r\n" + 
				"   ORG_FILE_NAME        VARCHAR(256),\r\n" + 
				"   FILE_BYTES            INTEGER                         not null,\r\n" + 
				"   FILE_EXT             VARCHAR(10),\r\n" + 
				"   UPLOADER             VARCHAR(50),\r\n" + 
				"   UPLOAD_TIME          TIMESTAMP,\r\n" + 
				"   APP_ID               VARCHAR(64)                    not null,\r\n" + 
				"   TENANT_ID            VARCHAR(64)                    not null,\r\n" + 
				"   ACCESS_TIMES         INTEGER,\r\n" + 
				"   CLASSIFY_CODE1       VARCHAR(64),\r\n" + 
				"   CLASSIFY_CODE2       VARCHAR(64),\r\n" + 
				"   THUMBNAIL1_HEIGHT    SMALLINT,\r\n" + 
				"   THUMBNAIL1_WIDTH     SMALLINT,\r\n" + 
				"   THUMBNAIL1_BYTES     INTEGER,\r\n" + 
				"   THUMBNAIL2_HEIGHT    SMALLINT,\r\n" + 
				"   THUMBNAIL2_WIDTH     SMALLINT,\r\n" + 
				"   THUMBNAIL2_BYTES     INTEGER,\r\n"+
				"   REMARKS              VARCHAR(256),\r\n" + 
				"   RECORD_EDIT_FLAG     SMALLINT,\r\n" + 
				"   primary key (ID)\r\n" + 
				")";
		dao.execute(ddl);

		ddl = "create unique index IX1_" + tableName + " on " + tableName + "(ACCESS_ID)";
		dao.execute(ddl);

		ddl = "create index IX2_" + tableName + " on " + tableName + "(APP_ID,TENANT_ID)";
		dao.execute(ddl);

		ddl = "create index IX3_" + tableName + " on " + tableName + "(APP_ID,CLASSIFY_CODE1,CLASSIFY_CODE2)";
		dao.execute(ddl);
	}

	/**创建一个带表名时间标记的记录id，格式：uuid_2020
	 * 
	 * @param tableSubPart
	 * @return 
	 * @author  wanghua
	 * @reviewer  
	 */
	private String newId(String tableSubPart) {
		String uuid = UUIDUtil.createCompressedUUID();
		String id = uuid+tableSubPart;
		return id;
	}

	private String getTableNameById(String id) {
		if(id == null)return null;
		String tableName = UploadFileTableName;
		int spIdx = id.lastIndexOf(TableSubPartSpltChar);
		if(spIdx > 0) {
			String tableSubPart = id.substring(spIdx);
			tableName = UploadFileTableName + tableSubPart;
		}
		return tableName;		
	}

	public UploadFile getUploadFile(String id) throws Exception{
		String tableName = getTableNameById(id);
		String sql = "select " + SelectFields + " from "+tableName +" where id=?";
		Map<String, Object> row = dao.queryDataRowMap(sql, new Object[] {id});
		UploadFile uploadFile = this.parseFrom(row);
		return uploadFile;
	}

	public UploadFileSimple getUploadFileSimple(String id) throws Exception {
		String tableName = getTableNameById(id);
		String selectFields = "ID,ACCESS_ID,ORG_FILE_NAME,"
		+ "FILE_BYTES,FILE_EXT,UPLOADER,UPLOAD_TIME,APP_ID,"
		+ "TENANT_ID,ACCESS_TIMES,CLASSIFY_CODE1,CLASSIFY_CODE2,REMARKS";
		String sql = "select " + selectFields + " from "+tableName +" where id=?";
		Map<String, Object> row = dao.queryDataRowMap(sql, new Object[] {id});
		UploadFileSimple uploadFile = new UploadFileSimple();
		RowMapper mapper = new RowMapper(row);
		uploadFile.setId(mapper.getString("ID"));
		uploadFile.setAccessId(mapper.getString("ACCESS_ID"));
		uploadFile.setOrgFileName(mapper.getString("ORG_FILE_NAME"));
		uploadFile.setFileBytes(mapper.get_long("FILE_BYTES"));
		uploadFile.setFileExt(mapper.getString("FILE_EXT"));
		uploadFile.setUploader(mapper.getString("UPLOADER"));
		uploadFile.setUploadTime(mapper.getDate("UPLOAD_TIME"));
		uploadFile.setAppId(mapper.getString("APP_ID"));
		uploadFile.setTenantId(mapper.getLong("TENANT_ID"));
		uploadFile.setAccessTimes(mapper.get_long("ACCESS_TIMES"));
		return uploadFile;
	}

	public UploadFile getUploadFileByAccessId(String accessId) throws Exception{
		String tableName = getTableNameById(accessId);
		String sql = "select " + SelectFields + " from "+tableName +" where ACCESS_ID=?";
		Map<String, Object> row = dao.queryDataRowMap(sql, new Object[] {accessId});
		UploadFile uploadFile = this.parseFrom(row);
		return uploadFile;
	}

	public void saveOrUpdateUploadFile(UploadFile upLoadFile) throws Exception{
		if(StringUtils.isEmpty(upLoadFile.getId())) {//insert
			String[] tableNameInfo = this.getTableNameAndCreateTable();
			String tableName = tableNameInfo[0];
			//String tableName = "ccbim_cloud.tms_upload_file";
			String tableSubPart = tableNameInfo[1];
			String sql = "insert into "+tableName+"(ID,ACCESS_ID,STORAGE_ID,FILE_PATH,ORG_FILE_NAME"
					+ ",FILE_BYTES,FILE_EXT,UPLOADER,UPLOAD_TIME,APP_ID"
					+ ",TENANT_ID,ACCESS_TIMES,CLASSIFY_CODE1,CLASSIFY_CODE2,REMARKS"
					+ ",THUMBNAIL1_HEIGHT,THUMBNAIL1_WIDTH,THUMBNAIL1_BYTES,THUMBNAIL2_HEIGHT,THUMBNAIL2_WIDTH,THUMBNAIL2_BYTES) "
					+ "values(?,?,?,?,? ,?,?,?,?,? ,?,?,?,?,? ,?,?,?,?,?,?)";
			String id = this.newId(tableSubPart);
			String accessId = this.newId(tableSubPart);
			upLoadFile.setId(id);
			upLoadFile.setAccessId(accessId);
			dao.insertDataRowBySql(sql, new Object[] {
				id,
				accessId,
				upLoadFile.getStorageId(),
				upLoadFile.getFilePath(),
				upLoadFile.getOrgFileName(),

				upLoadFile.getFileBytes(),
				upLoadFile.getFileExt(),
				upLoadFile.getUploader(),
				upLoadFile.getUploadTime(),
				upLoadFile.getAppId(),

				upLoadFile.getTenantId(),
				upLoadFile.getAccessTimes(),
				upLoadFile.getClassifyCode1(),
				upLoadFile.getClassifyCode2(),
				upLoadFile.getRemarks(),

				upLoadFile.getThumbnail1Height(),
				upLoadFile.getThumbnail1Width(),
				upLoadFile.getThumbnail1Bytes(),
				upLoadFile.getThumbnail2Height(),
				upLoadFile.getThumbnail2Width(),
				upLoadFile.getThumbnail2Bytes()
			});
		}else {//update
			String id = upLoadFile.getId();
			String tableName = getTableNameById(id);
			String sql = "update "+tableName+" set ACCESS_ID=?,STORAGE_ID=?,FILE_PATH=?,ORG_FILE_NAME=?"
					+ ",FILE_BYTES=?,FILE_EXT=?,UPLOADER=?,UPLOAD_TIME=?,APP_ID=?"
					+ ",TENANT_ID=?,ACCESS_TIMES=?,CLASSIFY_CODE1=?,CLASSIFY_CODE2=?,REMARKS=? "
					+ ",THUMBNAIL1_HEIGHT=?,THUMBNAIL1_WIDTH=?,THUMBNAIL1_BYTES=?,THUMBNAIL2_HEIGHT=?,THUMBNAIL2_WIDTH=?,THUMBNAIL2_BYTES=?"
					+ " where id=?";
			dao.updateDataRowBySql(sql, new Object[] {
				upLoadFile.getAccessId(),
				upLoadFile.getStorageId(),
				upLoadFile.getFilePath(),
				upLoadFile.getOrgFileName(),

				upLoadFile.getFileBytes(),
				upLoadFile.getFileExt(),
				upLoadFile.getUploader(),
				upLoadFile.getUploadTime(),
				upLoadFile.getAppId(),

				upLoadFile.getTenantId(),
				upLoadFile.getAccessTimes(),
				upLoadFile.getClassifyCode1(),
				upLoadFile.getClassifyCode2(),
				upLoadFile.getRemarks(),

				upLoadFile.getThumbnail1Height(),
				upLoadFile.getThumbnail1Width(),
				upLoadFile.getThumbnail1Bytes(),
				upLoadFile.getThumbnail2Height(),
				upLoadFile.getThumbnail2Width(),
				upLoadFile.getThumbnail2Bytes(),

				id
			});
		}
	}

	public int deleteUploadFile(String id) throws Exception {
		String tableName = getTableNameById(id);
		return dao.deleteDataRowBySql("delete from " + tableName + " where id=?", new Object[] {id});
	}

	private UploadFile parseFrom(Map<String, Object> row) {
		if(row == null)return null;
		UploadFile uploadFile = new UploadFile();
		RowMapper mapper = new RowMapper(row);
		uploadFile.setId(mapper.getString("ID"));
		uploadFile.setAccessId(mapper.getString("ACCESS_ID"));
		uploadFile.setStorageId(mapper.getString("STORAGE_ID"));
		uploadFile.setFilePath(mapper.getString("FILE_PATH"));
		uploadFile.setOrgFileName(mapper.getString("ORG_FILE_NAME"));
		uploadFile.setFileBytes(mapper.get_long("FILE_BYTES"));
		uploadFile.setFileExt(mapper.getString("FILE_EXT"));
		uploadFile.setUploader(mapper.getString("UPLOADER"));
		uploadFile.setUploadTime(mapper.getDate("UPLOAD_TIME"));
		uploadFile.setAppId(mapper.getString("APP_ID"));
		uploadFile.setTenantId(mapper.getLong("TENANT_ID"));
		uploadFile.setAccessTimes(mapper.get_long("ACCESS_TIMES"));
		uploadFile.setClassifyCode1(mapper.getString("CLASSIFY_CODE1"));
		uploadFile.setClassifyCode2(mapper.getString("CLASSIFY_CODE2"));
		uploadFile.setThumbnail1Height(mapper.getInt("THUMBNAIL1_HEIGHT"));
		uploadFile.setThumbnail1Width(mapper.getInt("THUMBNAIL1_WIDTH"));
		uploadFile.setThumbnail1Bytes(mapper.getInt("THUMBNAIL1_BYTES"));
		uploadFile.setThumbnail2Height(mapper.getInt("THUMBNAIL2_HEIGHT"));
		uploadFile.setThumbnail2Width(mapper.getInt("THUMBNAIL2_WIDTH"));
		uploadFile.setThumbnail2Bytes(mapper.getInt("THUMBNAIL2_BYTES"));
		uploadFile.setRemarks(mapper.getString("REMARKS"));
		return uploadFile;
	}
}
